//
// Created by lanlu on 2025/8/6.
//

#include <vector>
#include <string>
#include <stack>
#include <iostream>
using namespace std;

class Solution {
public:
    int evalRPN(vector<string> &tokens)
    {
        // 栈中只需要存储数字
        stack<int> s;
        // 遍历字符串数组
        for (string token: tokens)
        {
            // 因为运算符只有 +-*/ 非运算符即为数字
            if (token != "+" && token != "-" && token != "*" && token != "/")
            {
                // 字符串转为int stoi
                int num = stoi(token);
                s.push(num);
                continue;
            }
            // 处理运算符
            int num1 = s.top();
            s.pop();
            int num2 = s.top();
            s.pop();
            if (token == "+")
            {
                s.push(num1 + num2);
            }
            else if (token == "-")
            {
                s.push(num2 - num1);
            }
            else if (token == "*")
            {
                s.push(num1 * num2);
            }
            else if (token == "/")
            {
                s.push(num2 / num1);
            }
        }
        return s.top();
    }
};

int main()
{
    // vector<string> tokens = {"2", "1", "+", "3", "*"};
    vector<string> tokens = {"10","6","9","3","+","-11","*","/","*","17","+","5","+"};
    cout << Solution().evalRPN(tokens) << endl;
}
